package com.joysuch.wwyt.bp.entity;

import com.joysuch.wwyt.core.support.AutoSetCommonFieldListener;
import lombok.Data;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

import static javax.persistence.GenerationType.IDENTITY;

@EntityListeners({AuditingEntityListener.class, AutoSetCommonFieldListener.class})
@Entity
@Table(name = "wwyt_bp_emergency_defect")
@SQLDelete(sql = "update wwyt_bp_emergency_defect set DELETE_FLAG = '1' where id= ?")
@SQLDeleteAll(sql = "update wwyt_bp_emergency_defect set DELETE_FLAG = '1' where id= ?")
@Where(clause = "DELETE_FLAG = '0'")
@Data
public class BpEmergencyDefect implements Serializable {

    //整改计划id
    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "ID", unique = true, nullable = false)
    private Long id;

    //描述
    @Column(name = "DESCRIPTION")
    private String description;

    //是否需要整改:是;否
    @Column(name = "CORRECT")
    private String correct;

    //整改状态:0待整改;1已整改;2无需整改
    @Column(name = "STATE")
    private Integer state;

    //演练记录id
    @Column(name = "RECORD_ID")
    private Long recordId;

    @org.springframework.data.annotation.CreatedBy
    @Column(name = "CREATE_BY")
    private Long createBy;

    @org.springframework.data.annotation.CreatedDate
    @Column(name = "CREATE_TIME")
    private Date createTime;

    @org.springframework.data.annotation.LastModifiedBy
    @Column(name = "UPDATE_BY")
    private Long updateBy;

    @org.springframework.data.annotation.LastModifiedDate
    @Column(name = "UPDATE_TIME")
    private Date updateTime;

    @Column(name = "DELETE_FLAG")
    private String deleteFlag;

    @Column(name = "ORG_CODE")
    private String orgCode;

    @Column(name = "TENENT_ID")
    private Long tenentId;

    public int hashCode() {
        return new HashCodeBuilder().append(getId()).toHashCode();
    }

    public boolean equals(Object obj) {
        if (obj instanceof BpEmergencyDefect == false)
            return false;
        if (this == obj)
            return true;
        BpEmergencyDefect other = (BpEmergencyDefect) obj;
        return new EqualsBuilder().append(getId(), other.getId()).isEquals();
    }
}
